package cn.yiyuan.base.until;

import lombok.Data;

/**
 * @user m
 * @project system
 * @date 2023-10-27
 * @package cn.yiyuan.base.until
 */
@Data
public class AjaxResult {
//true 成功 false 失败
    private Boolean success = true;

//msg 存储操作结果
    private String msg = "操作成功";

//对象 存储返回数据
    private Object data;

//方法
//操作成功无返会数据
    public static AjaxResult success(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.success = true;
        ajaxResult.msg = "操作成功";
        return ajaxResult;
    }

    //操作成功有返回数据
    public static AjaxResult success(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.data = data;
        ajaxResult.success = true;
        ajaxResult.msg = "操作成功";
        return ajaxResult;
    }

    //传入一个msg  将msg重新赋值给msg   如果传入成功 就返回成功 .......
    public static AjaxResult success(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.success=true;
        ajaxResult.msg=msg;
        return ajaxResult;
    }

//错误
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.success=false;
        ajaxResult.msg=msg;
        return ajaxResult;
    }

    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.success=false;
        ajaxResult.msg="无参错误请求";
        return ajaxResult;
    }
}
